package com.woniu.car.controller;


import com.woniu.car.common.JWTUtil;
import com.woniu.car.common.ResponseEntity;
import com.woniu.car.parameter.UserInfoParam;
import com.woniu.car.service.TUserInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
 * <p>
 * 用户详情 前端控制器
 * </p>
 *
 * @author zhoubinbin
 * @since 2021-06-21
 */
@RestController
@RequestMapping("/tUserInfo")
@Api(tags = "用户详情接口")
public class TUserInfoController {
    @Resource
    private TUserInfoService userInfoService;


    @ApiOperation(value = "用户详情修改")
    @PutMapping("UpdateUserInfo")
    //用户详情修改
    public ResponseEntity updateUserInfo(@Valid UserInfoParam userInfoParam, HttpServletRequest request) throws Exception {
        return userInfoService.updateUserInfo(userInfoParam,request);
    }

    @ApiOperation(value = "用户详情查询")
    //查询用户详情
    @GetMapping("getUserInfro")
    public ResponseEntity getUserInfo(HttpServletRequest request) throws Exception {
        String token = request.getHeader("token");
        if (token==null){
            return new ResponseEntity(500,"您当前未登陆,请登陆后进行操作",null);
        }
        String id = JWTUtil.getId(token);
        Integer userId = Integer.parseInt(id);
        System.out.println(userId);
        return userInfoService.getUserInfo(userId);
    }

}

